<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta content="telephone=no" name="format-detection">
    <meta name="x5-fullscreen" content="true">
    <meta name="full-screen" content="yes">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_363663_xo7863s0yfmbzkt9.css"
          th:href="@{http://at.alicdn.com/t/font_363663_xo7863s0yfmbzkt9.css}">
    <link rel="stylesheet" href="plugins/weui/weui.min.css" th:href="@{/static/plugins/weui/weui.min.css}">
    <link rel="stylesheet" href="plugins/jquery-weui/css/jquery-weui.css" th:href="@{/static/plugins/jquery-weui/css/jquery-weui.css}">
    <link rel="stylesheet" href="plugins/swiper/css/swiper.min.css" th:href="@{/static/plugins/swiper/css/swiper.min.css}">
    <link rel="stylesheet" href="css/style.css" th:href="@{/static/css/style.css}">
    <!--basis script-->
    <script src="plugins/adaptive.js/adaptive.js" th:src="@{/static/plugins/adaptive.js/adaptive.js}"></script>
    <script src="plugins/jquery/jquery.min.js" th:src="@{/static/plugins/jquery/jquery.min.js}"></script>
    <script src="plugins/weui/weui.js" th:src="@{/static/plugins/weui/weui.js}"></script>
    <script src="plugins/jquery-weui/js/jquery-weui.min.js"
            th:src="@{/static/plugins/jquery-weui/js/jquery-weui.min.js}"></script>
    <script src="plugins/fastclick/fastclick.js" th:src="@{/static/plugins/fastclick/fastclick.js}"></script>
    <script src="plugins/vue/vue.js" th:src="@{/static/plugins/vue/vue.js}"></script>
    <script src="plugins/vue/axios.min.js" th:src="@{/static/plugins/vue/axios.min.js}"></script>
    <script src="plugins/vue/axios-tools.js" th:src="@{/static/plugins/vue/axios-tools.js}"></script>
    <script src="plugins/vue/ajax-tool.js" th:src="@{/static/plugins/vue/ajax-tool.js}"></script>
</head>
<body>
<div class="login-wrap">
    <dl class="login-header">
        <dt>移动药房</dt>
    </dl>
    <div class="login-box" id="login">
        <div class="weui-cell weui-cell_select">
            <div class="weui-cell__hd"><i class="iconfont icon-01"></i></div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="agency" v-model="agencyId">
                    <option selected="" value='0'>机构名称</option>
                    <option :value="item.aid" v-for="item in agencylist">{{item.name}}</option>
                </select>
            </div>
        </div>
        <div class="weui-cell weui-cell_select">
            <div class="weui-cell__hd"><i class="iconfont icon-ico-user"></i></div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="userid" v-model="userId">
                    <option selected="" value="0">登录名</option>
                    <option :value="item.id.name" v-for="item in userlist">{{item.id.name}}</option>
                </select>
            </div>
        </div>
        <div class="weui-cell weui-cell_select">
            <div class="weui-cell__hd"><i class="iconfont icon-01"></i></div>
            <div class="weui-cell__bd">
                <select class="weui-select" name="agency" v-model="drughomeid">
                    <option selected="" value='0'>药房</option>
                    <option :value="item.id.id" v-for="item in drughomelist">{{item.name}}({{item.id.id}})</option>
                </select>
            </div>
        </div>
        <div class="weui-cell">
            <div class="weui-cell__hd"><i class="iconfont icon-21"></i></div>
            <div class="weui-cell__bd">
                <input class="weui-input" type="password" placeholder="密码" v-model="pwd">
            </div>
        </div>
        <div class="weui-btn-area">
            <a class="weui-btn weui-btn_primary" @click="onlogin" href="#">登录</a>
        </div>
        <label class="weui-agree">
            <a class="weui-agree__text">
                忘记密码？
            </a>
        </label>
    </div>
</div>
<script>
    $(function () {
        var login = new Vue({
            el: '#login',
            data: {
                agencyId: 0,
                userId: 0,
                pwd: '',
                drughomeid: 0
            },
            computed: {
                agencylist: function () {
                    let res = []
                    //axios http访问后台 获取机构信息列表
                    ajaxsync({
                        url: '/mphs/hospital/findall',
                        method: 'get',
                        datajson: null,
                        succ: function (data) {
                            res = data.hospitals
                        }
                    })
                    return res
                },
                userlist: function () {
                    console.info('userlist-change:'+this.agencyId)
                    if(this.agencyId == 0){
                        this.userId = 0
                        return []
                    }
                    let res = []
                    //通过机构ID获取用户列表
                    ajaxsync({
                        url: '/mphs/userinfo/findbyhosp?aid='+this.agencyId,
                        method: 'get',
                        datajson: null,
                        succ: function (data) {
                            res = data.userinfos
                        }
                    })
                    return res
                },
                drughomelist: function () {
                    console.info('drughomelist-change:'+this.agencyId)
                    if(this.agencyId == 0){
                        this.drughomeid = 0
                        return []
                    }
                    let res = []
                    ajaxsync({
                        url: '/mphs/medhouse/ag?aid='+this.agencyId,
                        method: 'get',
                        datajson: null,
                        succ: function (data) {
                            res = data.houses
                        }
                    })
                    return res
                }
            },
            methods: {
                //登陆
                onlogin: function () {
                    let _this = this
                    if(_this.agencyId == 0){
                        $.alert("请选择机构", "警告");
                        return false
                    }
                    if(_this.userId == 0){
                        $.alert("请选择用户", "警告");
                        return false
                    }
                    if(_this.drughomeid == 0){
                        $.alert("请选择药房", "警告");
                        return false
                    }
                    if(_this.pwd == 0){
                        $.alert("请填写密码", "警告");
                        return false
                    }
                    let lparam = {
                        aid: _this.agencyId,
                        uname: _this.userId,
                        password: _this.pwd,
                        house: _this.drughomeid
                    }
                    axiosconfig({
                        url: '/login',
                        method: 'get',
                        params: lparam,
                        succ: function (data) {
                            console.info(data)
                            sessionStorage.setItem("login", JSON.stringify(lparam))
                            location.href = 'choose.html'
                        }
                    })

                }
            }
        })
    })
</script>
</body>
</html>